package com.ruoyi.project.yingyu.activityReg.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.yingyu.activity.service.IActivityService;
import com.ruoyi.project.yingyu.activityReg.domain.ActivityReg;
import com.ruoyi.project.yingyu.activityReg.service.IActivityRegService;

/**
 * 活动报名表Controller
 * 
 * @author ruoyi
 * @date 2019-12-02
 */
@Controller
@RequestMapping("/yingyu/activityReg")
public class ActivityRegController extends BaseController {
	private String prefix = "yingyu/activityReg";

	@Autowired
	private IActivityRegService activityRegService;

	@Autowired
	private IActivityService activityService;

	@RequiresPermissions("yingyu:activityReg:view")
	@GetMapping("/{activityId}")
	public String activityReg(@PathVariable("activityId") Integer activityId, ModelMap mmap) {
		mmap.put("activity", activityService.selectActivityById(activityId));
		return prefix + "/activityReg";
	}

	/**
	 * 查询活动报名表列表
	 */
	@RequiresPermissions("yingyu:activityReg:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ActivityReg activityReg) {
		startPage();
		List<ActivityReg> list = activityRegService.selectActivityRegList(activityReg);
		return getDataTable(list);
	}

	/**
	 * 导出活动报名表列表
	 */
	@RequiresPermissions("yingyu:activityReg:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(ActivityReg activityReg) {
		List<ActivityReg> list = activityRegService.selectActivityRegList(activityReg);
		ExcelUtil<ActivityReg> util = new ExcelUtil<ActivityReg>(ActivityReg.class);
		return util.exportExcel(list, "activityReg");
	}

	/**
	 * 新增活动报名表
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存活动报名表
	 */
	@RequiresPermissions("yingyu:activityReg:add")
	@Log(title = "活动报名表", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ActivityReg activityReg) {
		return toAjax(activityRegService.insertActivityReg(activityReg));
	}

	/**
	 * 修改活动报名表
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		ActivityReg activityReg = activityRegService.selectActivityRegById(id);
		mmap.put("activityReg", activityReg);
		return prefix + "/edit";
	}

	/**
	 * 修改保存活动报名表
	 */
	@RequiresPermissions("yingyu:activityReg:edit")
	@Log(title = "活动报名表", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ActivityReg activityReg) {
		return toAjax(activityRegService.updateActivityReg(activityReg));
	}

	/**
	 * 删除活动报名表
	 */
	@RequiresPermissions("yingyu:activityReg:remove")
	@Log(title = "活动报名表", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(activityRegService.deleteActivityRegByIds(ids));
	}
}
